﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mime;
using System.Text;
using System.Windows.Controls;

namespace AuctionHouse
{
    public delegate void HighestBidHandler();
   public class Lot : ILot
    {
       public event HighestBidHandler newHighestBidRecieved;

        private string _lotNumber ;
        private string _category;
       
        private string _description;
        private string _auctionDate;
        private Image _image;
        
        private int _valuation;
        private int _reservePrice;
        private int _age;
        private string _condition;
        private decimal _CurrentHighestBid;
        private string _CurrentWinner;
        // Our object for locking
        private object _lotLock;

        public Lot()
        {
            Condition = "";
            Age = 0;
            ReservePrice = 0;
            Valuation = 0;
            Image = null;
            AuctionDate = "";
            Description = "";
            Category = "FirstCat";
            LotNumber = "";
        }


        public Lot(string condition, int age, int reservePrice, int valuation, Image image, 
                    string auctionDate, string description, string category, string lotNumber)
        {
            Condition = condition;
            Age = age;
            ReservePrice = reservePrice;
            Valuation = valuation;
            Image = image;
            AuctionDate = auctionDate;
            Description = description;
            Category = category;
            LotNumber = lotNumber;
        }

        public decimal HighestBid
        {
            get { return _CurrentHighestBid; }            
        }

        public string LotNumber
        {
            get { return _lotNumber; }
            set
            {
                lock (_lotLock) // limit access to this field for the duration of the lock
                {
                    _lotNumber = value;
                }
                
            }
        }

        public string Category
        {
            get { return _category; }
            set
            {
                lock (_lotLock)
                {
                    _category = value;
                }
               
            }
        }

        public string Description
        {
            get { return _description; }
            set
            {
                lock (_lotLock)
                {
                    _description = value; 
                }
                
            }
        }

        public string AuctionDate
        {
            get { return _auctionDate; }
            set
            {
                lock (_lotLock)
                {
                    _auctionDate = value;
                }
                
            }
        }

        public Image Image
        {
            get { return _image; }
            set
            {
                lock (_lotLock)
                {
                    _image = value; 
                }
               
            }
        }

        public int Valuation
        {
            get { return _valuation; }
            set
            {
                lock (_lotLock)
                {
                    
                }
                _valuation = value;
            }
        }

        public int ReservePrice
        {
            get { return _reservePrice; }
            set
            {
                lock (_lotLock)
                {
                    _reservePrice = value;
                }
                
            }
        }

        public int Age
        {
            get { return _age; }
            set
            {
                lock (_lotLock)
                {
                     _age = value;
                }
               
            }
        }

        public string Condition
        {
            get { return _condition; }
            set
            {
                lock (_lotLock)
                {
                     _condition = value;
                }
               
            }
        }


        #region Methods
            public void UpdateHighestBidder(decimal amount, string Name)
            {
                _CurrentWinner = Name;
                _CurrentHighestBid = amount;
                newHighestBidRecieved();
            }
        #endregion
        
    }
}
